/*
 * Created on Jul 11, 2004
 */
package dk.aiszone.lang.autosource.generatorobjects;

import dk.aiszone.lang.autosource.generatorobjects.interfaces.GeneratorObject;

/**
 * Representation of a simple argument used in <code>MethodDeclarations</code>.<br>
 * Example:
 * 
 * <pre>
 *        public void test(String arg1, int arg2)
 * </pre>
 * 
 * @author <a href="mailto:ais@mail.dk">Ais</a>
 * @since 1.0
 * @version 1.0
 * @see MethodDeclaration
 */
public class Argument extends GeneratorObject implements Cloneable {

    private String javaDoc;
    private String name;
    private Class type;

    /**
     * Default constructor for the <code>Argument</code> class.<br>
     * Usage of the constructor requires the user to later on assign values to <code>name</code> and <code>type</code>.
     * 
     * @see #setName(String)
     * @see #setType(Class)
     */
    public Argument() {
        super();
    }

    /**
     * Constructor for the <code>Argument</code> class.<br>
     * 
     * @param type
     *            The <code>Argument</code> class
     * @param name
     *            The name of the <code>Argument</code>.
     */
    public Argument(Class type, String name) {
        this.type = type;
        this.name = name;
    }

    /**
     * Constructor for the <code>Argument</code> class.<br>
     * 
     * @param type
     *            The <code>Argument</code> class
     * @param name
     *            The name of the <code>Argument</code>.
     * @param javaDoc
     *            JavaDoc for the <code>Argument</code><br>
     *            See also {@link #setJavaDoc(String)}
     */
    public Argument(Class type, String name, String javaDoc) {
        this.type = type;
        this.name = name;
        this.javaDoc = javaDoc;
    }

    /**
     * Creates a new argument based on a <code>Variable</code>.<br>
     * The constructor extracts the name and type from the variable
     * 
     * @param var
     *            <code>Variable</code> to construct <code>Argument</code> from
     */
    public Argument(Variable var) {
        this(var.getType(), var.getName());
    }

    /**
     * Retrieve the JavaDoc of the <code>Argument</code>.
     * 
     * @return The assigned JavaDoc
     */
    public String getJavaDoc() {
        return javaDoc;
    }

    /**
     * Get name of argument
     * 
     * @return The name of the argument
     */
    public String getName() {
        return name;
    }

    /**
     * Get the type of argument
     * 
     * @return Class representing the class type of the argument
     * @see Class
     */
    public Class getType() {
        return type;
    }

    /**
     * Assign a JavaDoc description to the argument.<br>
     * This is later on extracted by the formatter, and added to the JavaDoc of the <code>MethodDeclaration</code> in which this
     * <code>Argument</code> is used.
     * 
     * @param javaDoc
     *            The description of the <code>Argument</code>.
     */
    public void setJavaDoc(String javaDoc) {
        this.javaDoc = javaDoc;
    }

    /**
     * Set or replace the current name of the <code>Argument</code> with the supplied one.
     * 
     * @param name
     *            New <code>Argument</code> name.
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Set or replace the current type of the <code>Argument</code> with the supplied one.
     * 
     * @param type
     *            New <code>Argument</code> type.
     */
    public void setType(Class type) {
        this.type = type;
    }

    /**
     * Creates a clone of the <code>Argument</code>.
     * 
     * @return A new instance of the <code>Argument</code> class based on <code>this</code> class.
     */
    @Override
    protected Object clone() {
        return new Argument(type, name);
    }
}